home *** CD-ROM | disk | FTP | other *** search
/ Delphi 2.0 - Programmer's Utilities Power Pack / Delphi 2.0 Programmer's Utilities Power Pack.iso / m_to_r / reporter / summrpt1.pas < prev   
Encoding:
Pascal/Delphi Source File  |  1996-09-15  |  7.4 KB  |  252 lines

  1. unit Summrpt1;
  2.  
  3. interface
  4.  
  5. uses
  6.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  7.   Forms, Dialogs, StdCtrls, DB, DBTables, Reports;
  8.  
  9. type
  10.   TForm1 = class(TForm)
  11.     Button1: TButton;
  12.     Table1: TTable;
  13.     Table2: TTable;
  14.     DataSource1: TDataSource;
  15.     procedure Button1Click(Sender: TObject);
  16.   private
  17.     { Private declarations }
  18.  
  19.     { declare report variables }
  20.     NumCustomers, NumOrders : Word;
  21.   public
  22.     { Public declarations }
  23.     Procedure ReportInit;
  24.     Procedure ReportDone;
  25.  
  26.     Procedure PrintHeader     ( HeaderBand  : tFixedReportBand;
  27.                                 var Status  : tBandStatus );
  28.     Procedure PrintFooter     ( FooterBand  : tFixedReportBand;
  29.                                 var Status  : tBandStatus );
  30.  
  31.     Procedure ReportSummarySetup ( MasterBand : tFixedReportBand;
  32.                                    var Status : tBandStatus );
  33.     Procedure ReportSummary      ( MasterBand : tFixedReportBand;
  34.                                    var Status : tBandStatus );
  35.  
  36.     Procedure PrintCustomer   ( MasterBand  : tFixedReportBand;
  37.                                 var Status  : tBandStatus );
  38.     Procedure CustomerSummary ( SummaryBand : tFixedReportBand;
  39.                                 var Status  : tBandStatus );
  40.  
  41.     Procedure PrintOrder      ( MasterBand  : tFixedReportBand;
  42.                                 var Status  : tBandStatus );
  43.  
  44.   end;
  45.  
  46. var
  47.   Form1: TForm1;
  48.  
  49. implementation
  50. Uses pStatus;
  51.  
  52. {$R *.DFM}
  53.  
  54. procedure tForm1.ReportInit;
  55. Begin
  56.      { Don't allow the user to use the main form while the report
  57.        is printing }
  58.      Enabled := False;
  59.  
  60.      { Set up the Print Status Dialog }
  61.      With PrintStatusForm Do
  62.      Begin
  63.           ProgressGauge.MaxValue := 100;
  64.           ProgressGauge.Progress := 0;
  65.           CurrentPage := 1;
  66.           PrintStatus := 'Loading data...';
  67.           PrinterName := Reporter.Printers[Reporter.PrinterIndex];
  68.           Show;
  69.           UpdateStatus;
  70.      End;
  71.  
  72.      Table2.Open;
  73.      PrintStatusForm.ProgressGauge.MaxValue := Table2.RecordCount;
  74.      Table1.Open;
  75.  
  76.      { Set the Report margins }
  77.      Reporter.TopMargin.AsInches := 2.0;
  78.      Reporter.LeftMargin.AsInches := 1.0;
  79.      Reporter.RightMargin.AsInches := 1.0;
  80.      Reporter.BottomMargin.AsInches := 1.0;
  81.  
  82.  
  83.      { set the Report's default units }
  84.      Reporter.PreferredUnit := puInches;
  85.  
  86.      { set the Report's initial font }
  87.      Reporter.Canvas.Font.Size := 14;
  88.  
  89.      PrintStatusForm.PrintStatus := 'Printing...';
  90.      PrintStatusForm.UpdateStatus;
  91. End;
  92.  
  93. procedure tForm1.ReportDone;
  94. Begin
  95.      { Close Tables and Print status dialog }
  96.      Table1.Close;
  97.      Table2.Close;
  98.  
  99.      { Re-Enable main form before closing status dialog }
  100.      Enabled := True;
  101.  
  102.      PrintStatusForm.Close;
  103. End;
  104.  
  105. procedure tForm1.PrintHeader (     HeaderBand : tFixedReportBand;
  106.                                var Status     : tBandStatus );
  107. Begin
  108.      With Reporter, HeaderBand Do
  109.      Begin
  110.           { save old font and set new font }
  111.           SaveFont;
  112.           Canvas.Font.Size := 24;
  113.           Canvas.Font.Name := 'Times New Roman';
  114.  
  115.  
  116.           BoxTextOut ( 'Customer Order Detail',
  117.                        ttaBandHCenter + ttaBandVCenter,
  118.                        btBox,
  119.                        20,
  120.                        3,
  121.                        stBottomLeft,
  122.                        20 );
  123.  
  124.           { restore previous font }
  125.           RestoreFont;
  126.  
  127.      End;
  128. End;
  129.  
  130. procedure tForm1.PrintFooter (     FooterBand : tFixedReportBand;
  131.                                var Status     : tBandStatus );
  132. Begin
  133.      With FooterBand, Reporter Do
  134.      Begin
  135.           Canvas.MoveTo ( Left, Top );
  136.           Canvas.LineTo ( Right, Top );
  137.           TopOfBand;
  138.           AdjustY ( 0.1 );
  139.  
  140.           Reporter.SaveFont;
  141.           Reporter.Canvas.Font.Size := 8;
  142.           Reporter.Canvas.Font.Name := 'Times New Roman';
  143.  
  144.           TextOut ( 'Customer Order Detail', ttaLeftMargin );
  145.           TextOut ( 'Page ' + IntToStr(PageNumber), ttaRightMargin );
  146.  
  147.           Reporter.RestoreFont;
  148.      End;
  149. End;
  150.  
  151.  
  152. procedure tForm1.ReportSummarySetup (     MasterBand : tFixedReportBand;
  153.                                       var Status     : tBandStatus );
  154. Begin
  155.      { initialize report variables for this group }
  156.      NumCustomers := 0;
  157. End;
  158.  
  159. procedure tForm1.ReportSummary (     MasterBand : tFixedReportBand;
  160.                                  var Status     : tBandStatus );
  161. Begin
  162.      With MasterBand Do
  163.      Begin
  164.           { Give the summary a little extra space before printing }
  165.           NextLine;
  166.  
  167.           BoxTextOut ( 'Number of customers with more than three orders: ' +
  168.                        IntToStr ( NumCustomers ),
  169.                        ttaLeft,
  170.                        btTop, 10, 3,
  171.                        stNone, 0);
  172.      End;
  173.  
  174.      { Tell the reporter the report is done }
  175.      Status := bsDone;
  176. End;
  177.  
  178. procedure tForm1.PrintCustomer (     MasterBand : tFixedReportBand;
  179.                                  var Status     : tBandStatus );
  180. Begin
  181.      { Print out the group's name and initialize this group's report variables }
  182.      MasterBand.TextOut ( Table1.FieldByName ( 'Company' ).AsString, ttaLeft );
  183.      NumOrders := 0;
  184. End;
  185.  
  186. procedure tForm1.CustomerSummary (     SummaryBand : tFixedReportBand;
  187.                                    var Status      : tBandStatus );
  188. Begin
  189.      { Output the group's report variables }
  190.      SummaryBand.BoxTextOut ( '# Orders for ' +
  191.                            Table1.FieldByName ( 'Company' ).AsString +
  192.                            ': ' +
  193.                            IntToStr(NumOrders),
  194.                            ttaLeft,
  195.                            btTop, 10, 3,
  196.                            stNone, 0);
  197.      { Put an extra line at the bottom of the summary band }
  198.      SummaryBand.NextLine;
  199.  
  200.      { Increment a report variable }
  201.      If NumOrders > 3 Then
  202.         Inc ( NumCustomers );
  203.  
  204.      { advanec the table and set the report status }
  205.      Table1.Next;
  206.      If PrintStatusForm.Canceled Then
  207.         Status := bsAbort
  208.      Else If Table1.EOF Then
  209.           Status := bsDone;
  210. End;
  211.  
  212. procedure tForm1.PrintOrder (     MasterBand : tFixedReportBand;
  213.                               var Status     : tBandStatus );
  214. Begin
  215.      { Output the Order No }
  216.      MasterBand.TabTo ( 0.5 );
  217.      MasterBand.TextOut ( 'Order No. ' + Table2.FieldByName ( 'OrderNo' ).AsString, ttaLeft );
  218.  
  219.      { Increment a report variable }
  220.      Inc ( NumOrders );
  221.  
  222.      { update the Print Status dialog }
  223.      PrintStatusForm.ProgressGauge.Progress := PrintStatusForm.ProgressGauge.Progress + 1;
  224.      PrintStatusForm.CurrentPage := Reporter.PageNumber;
  225.      PrintStatusForm.UpdateStatus;
  226.  
  227.      { advance the orders table and set the report status }
  228.      Table2.Next;
  229.      If PrintStatusForm.Canceled Then
  230.         Status := bsAbort
  231.      Else If Table2.EOF Then
  232.           Status := bsDone;
  233. End;
  234.  
  235. procedure TForm1.Button1Click(Sender: TObject);
  236. begin
  237.      { Set the bands the Reporter will be printing }
  238.      Reporter.OnReportInit := ReportInit;
  239.      Reporter.OnReportDone := ReportDone;
  240.  
  241.      Reporter.AddHeader ( PrintHeader );
  242.      Reporter.AddFooter ( PrintFooter );
  243.  
  244.      Reporter.AddDetail ( Nil, PrintOrder );
  245.      Reporter.AddGroup  ( Nil, PrintCustomer, CustomerSummary );
  246.      Reporter.AddGroup  ( Nil, ReportSummarySetup, ReportSummary );
  247.  
  248.      Reporter.Run;
  249. end;
  250.  
  251. end.
  252.